package jp.syuriken.snsw.terenaibot;

import java.util.Date;
import java.util.regex.Matcher;

import jp.syuriken.snsw.terenaibot.format.PrecompiledSyntax;

/**
 * {@link PostWrapper}を{@link PostWrapper2}と互換性をもたせるためのクラスです。
 * このクラスは互換性を持たせるためだけに使用されるべきです。
 * 
 * @author $Author: snswinhaiku.lo@gmail.com $
 */
public class InterchangablePostWrapper extends PostWrapper2 {
	
	private class InterchangablePost extends Post2 {
		
		private Post post;
		

		public InterchangablePost(Post post) {
			this.post = post;
		}
		
		@Override
		public Date getCreatedAt() {
			return null;
		}
		
		@Override
		public String getInReplyToPostId() {
			return post.getInReplyToPostId();
		}
		
		@Override
		public String getInReplyToUserId() {
			return post.getInReplyToUserId();
		}
		
		@Override
		public Object getOriginal() {
			return post.getOriginal();
		}
		
		@Override
		public String getPostActualText() {
			return getPostText();
		}
		
		@Override
		public String getPostClassName() {
			return "PostWrapperIntegration#IntegrationPost";
		}
		
		@Override
		public String getPostId() {
			return post.getPostId();
		}
		
		@Override
		public String getPostText() {
			return post.getPostText();
		}
		
		@Override
		public PostType getPostType() {
			return null;
		}
		
		@Override
		public String getSource() {
			return post.getSource();
		}
		
		@Override
		public String getUser() {
			return post.getUser();
		}
		
		@Override
		public String getUserName() {
			return post.getUserName();
		}
		
		@Override
		public boolean isRepost() {
			return false;
		}
		
	}
	
	/**
		 * TODO snsoftware
		 * 
		 * @author $Author: snswinhaiku.lo@gmail.com $	 */
	@SuppressWarnings("serial")
	public class InterchangableWrapperException extends WrapperException2 {
		
		private WrapperException exception;
		

		/**
		 * インスタンスを生成する。
		 * 
		 * @param e 前バージョンのWrapperException
		 */
		public InterchangableWrapperException(WrapperException e) {
			super();
		}
		
		@Override
		public String getErrorDescription() {
			return exception.getErrorDescription();
		}
		
		@Override
		public String getErrorName() {
			return exception.getErrorName();
		}
		
		@Override
		public Object getRateLimitStatus() {
			return exception.getRateLimitStatus();
		}
		
		@Override
		public int getStatusCode() {
			return exception.getStatusCode();
		}
		
	}
	

	private PostWrapper postWrapper;
	

	/**
	 * インスタンスを生成する。
	 * 
	 * @param postWrapper ポストラッパ
	 */
	public InterchangablePostWrapper(PostWrapper postWrapper) {
		this.postWrapper = postWrapper;
	}
	
	@Override
	public boolean exceedApiLimitation() {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public boolean exceedPostLimitation() {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public boolean follow(String userId) {
		return false;
	}
	
	@Override
	public UserInfo[] getFollowers(boolean doCleanCache) {
		return new UserInfo[] {};
	}
	
	@Override
	public UserInfo[] getFollowing(boolean doCleanCache) {
		return new UserInfo[] {};
	}
	
	@Override
	public Post2[] getMentions() {
		return new Post2[] {};
	}
	
	@Override
	public Post2 getPost(String postId) throws IllegalStateException, WrapperException2 {
		try {
			return new InterchangablePost(postWrapper.getPost(postId));
		} catch (WrapperException e) {
			throw new InterchangableWrapperException(e);
		}
	}
	
	@Override
	public Object getPostActionClass() {
		return postWrapper.getPostActionClass();
	}
	
	@Override
	public Post2[] getPrivateMessage() {
		return new Post2[] {};
	}
	
	@Override
	public Post2[] getTimeline() {
		return new Post2[] {};
	}
	
	@Override
	public UserInfo getUserInfo() {
		return null; // TODO
	}
	
	@Override
	public UserInfo getUserInfo(String userId) {
		return null;
	}
	
	@Override
	public String getUserName() throws IllegalStateException, WrapperException2 {
		try {
			return postWrapper.getUserName();
		} catch (WrapperException e) {
			throw new InterchangableWrapperException(e);
		}
	}
	
	@Override
	public String getWrapperName() {
		return postWrapper.getWrapperName();
	}
	
	@Override
	public Post2 post(String poststr) throws IllegalStateException, WrapperException2 {
		try {
			return new InterchangablePost(postWrapper.post(poststr));
		} catch (WrapperException e) {
			throw new InterchangableWrapperException(e);
		}
	}
	
	@Override
	public Post2 postInQuote(PrecompiledSyntax postFormat, Matcher matcher, Post2 inReplyTo)
			throws IllegalStateException, WrapperException2 {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public Post2 postInQuote(String postString, Post2 inReplyTo) throws IllegalStateException {
		return NullPost2.getInstance();
	}
	
	@Override
	public Post2 postInReply(PrecompiledSyntax postFormat, Matcher matcher, Post2 inReplyTo)
			throws IllegalStateException, WrapperException2 {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public Post2 postInReply(String postString, Post2 inReplyTo) throws IllegalStateException {
		return NullPost2.getInstance();
	}
	
	@Override
	public Post2 postInUserCall(PrecompiledSyntax postFormat, Matcher matcher, UserInfo userId)
			throws IllegalStateException, WrapperException2 {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public Post2 postInUserCall(String postString, UserInfo userId) {
		return NullPost2.getInstance();
	}
	
	@Override
	public Post2 sendPrivateMessage(String pmString, String userId) {
		return NullPost2.getInstance();
	}
	
}
